home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com(Pete)
- Newsgroups: comp.lang.c++
- Subject: Re: Newbie Q: Is there a Static pointer?
- Date: 28 Jan 1996 15:49:44 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4eg5uo$67o@news1.usa.pipeline.com>
- NNTP-Posting-Host: pipe4.h1.usa.pipeline.com
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline USA v3.3.0
-
- On Jan 27, 1996 22:35:16 in article <Newbie Q: Is there a Static pointer?>,
- 'ua187@freenet.Victoria.BC.CA (Alex Walker)' wrote:
-
-
- > I'm learning C++ and at the moment making a doubly linked-list.
- > I'd like to have a pointer to an object of which there is only 1
- > copy and all memeber of the class (each node in the list) can use it.
- > This sounds like a static pointer, but does such an animal exists??.
- > I can't seem to find any info on anything like this, (typical for
- > a newbie eh?)
- >
- Yes. Example:
-
- Header file:
- class SomeObject;
-
- class Node
- {
- public:
- ... stuff
- static SomeObject * pSomeObject;
- };
-
- In any source file:
- SomeObject Node::pSomeObject = 0;
-
- Then, in your main(), before you start working with the list,
- initialize the static member something like:
-
- Node::pSomeObject = new SomeObject(....);
-
- Of course, if SomeObject is already created in global memory, just
- give its address instead. Also, pSomeObject member must be
- accessible to main or you must provide a Set function for it.
-
- --
- Pete Grant
- Kalevi, Inc.
- Object Oriented Software Development
-